package com.zlll.winner.controller.hot;

import com.alibaba.fastjson.JSONObject;
import com.zlll.winner.business.model.todayHot.TodayHot;
import com.zlll.winner.business.service.todayHot.ITodayHotService;
import com.zlll.winner.common.BaseController;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 今日热点
 */
@RestController
@RequestMapping(value = "/hot")
public class HotController extends BaseController {

    @Reference
    private ITodayHotService todayHotService;

    @PostMapping("saveTodayHot")
    public Object saveTodayHot(@RequestBody JSONObject data){
        TodayHot todayHot = data.toJavaObject(TodayHot.class);
        return todayHotService.saveTodayHot(todayHot,getUser());
    }

    @PostMapping("updateTodayHot")
    public Object updateTodayHot(@RequestBody JSONObject data){
        TodayHot todayHot = data.toJavaObject(TodayHot.class);
        return todayHotService.updateTodayHot(todayHot,getUser());
    }

    @PostMapping("/getTodayHotList")
    public Object getTodayHotList(@RequestBody JSONObject data){
        Integer pageSize = data.getInteger("pageSize") == null ? 20 :data.getInteger("pageSize");
        Integer pageNo = data.getInteger("pageNo") == null ? 1 :data.getInteger("pageNo");
        Long startTime = data.getLong("startTime");
        Long endTime = data.getLong("endTime");
        String title = data.getString("title");
        return todayHotService.getTodayHotList(title,startTime,endTime,pageSize,pageNo);
    }

    @PostMapping("/deleteTodayHot")
    public Object deleteTodayHot(@RequestBody JSONObject data){
        Long id = data.getLong("id");
        return todayHotService.deleteTodayHot(id,getUser());
    }
}
